home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / Game.as < prev    next >
Encoding:
Text File  |  2007-09-27  |  30.2 KB  |  838 lines

  1. class Game
  2. {
  3.    var mcRef;
  4.    var nNeedInitialLevelPause;
  5.    var oWinPopUp;
  6.    var oULLosePopUp;
  7.    var oMenuPopUp;
  8.    var oHelpPopUp;
  9.    var oConfirmPopUp;
  10.    var oObjectivesPopUp;
  11.    var oTransition;
  12.    var oTransitionMiniGameStart;
  13.    var oTransitionMiniGameEnd;
  14.    var oPlayerStatus;
  15.    var oGameTimer;
  16.    var bTimeOverTriggered;
  17.    var sPlayMode;
  18.    var oLevel;
  19.    var nObjectivesCloseTimer;
  20.    var oMiniGame;
  21.    var sCurrentSection;
  22.    var oTargetLevelData;
  23.    var nNewLevelTargetRow;
  24.    var nConfirmContext;
  25.    var oLevelToDelete;
  26.    var oLevelSelector;
  27.    var bTestingUserLevel;
  28.    var nPlayLevelType;
  29.    var sDeleteLevelName;
  30.    var nMoonStonesCatched;
  31.    var nMiniStonesCatched;
  32.    var nAwardedNPs;
  33.    var oTestLevel;
  34.    var sTargetSection;
  35.    var oMusicGameGround;
  36.    var oMusicGameSky;
  37.    var nGameStatus;
  38.    var nLatestHelpPage;
  39.    var oLevelEditor;
  40.    var nCurrentShownScore;
  41.    static var oCtrl;
  42.    static var SECTION_LEVEL_SELECT_STORY = "LevelSelectStory";
  43.    static var SECTION_LEVEL_SELECT_USER = "LevelSelectUser";
  44.    static var SECTION_GAME = "Game";
  45.    static var SECTION_EDITOR = "Edit";
  46.    static var CONFIRM_CONTEXT_DELETE_LEVEL = 1;
  47.    static var CONFIRM_CONTEXT_QUIT_GAME = 2;
  48.    static var GAME_STATUS_SIDESCROLLER = 1;
  49.    static var GAME_STATUS_MINIGAME = 2;
  50.    static var DEPTH_SIDESCROLLER = 150;
  51.    static var DEPTH_MINIGAME = 250;
  52.    static var HUD_POINTS_UPDATE_RATE = 120;
  53.    static var STAGE_WIDTH = 600;
  54.    static var STAGE_HEIGHT = 300;
  55.    static var aNP_BY_SCORE = [{nMin:-Infinity,nMax:99999,nPts:1},{nMin:100000,nMax:124999,nPts:2},{nMin:125000,nMax:149999,nPts:3},{nMin:150000,nMax:174999,nPts:5},{nMin:175000,nMax:Infinity,nPts:10}];
  56.    function Game(__mcRef, __bStoryMode)
  57.    {
  58.       this.mcRef = __mcRef;
  59.       Game.oCtrl = this;
  60.       this.nNeedInitialLevelPause = -1;
  61.       this.oWinPopUp = new Library.BasicPopUp(this.mcRef.mcPopups.mcWin);
  62.       this.oWinPopUp.Listener = this;
  63.       Main.Instance.doAddListener(this.oWinPopUp);
  64.       this.oULLosePopUp = new Library.BasicPopUp(this.mcRef.mcPopups.mcULLose);
  65.       this.oULLosePopUp.Listener = this;
  66.       Main.Instance.doAddListener(this.oULLosePopUp);
  67.       this.oMenuPopUp = new Library.BasicPopUp(this.mcRef.mcPopups.mcMenu);
  68.       this.oMenuPopUp.Listener = this;
  69.       Main.Instance.doAddListener(this.oMenuPopUp);
  70.       this.oHelpPopUp = new Library.BasicPopUp(this.mcRef.mcPopups.mcHelp);
  71.       this.oHelpPopUp.Listener = this;
  72.       Main.Instance.doAddListener(this.oHelpPopUp);
  73.       this.oConfirmPopUp = new Library.BasicPopUp(this.mcRef.mcPopups.mcConfirm);
  74.       this.oConfirmPopUp.Listener = this;
  75.       Main.Instance.doAddListener(this.oConfirmPopUp);
  76.       this.oObjectivesPopUp = new Library.BasicPopUp(this.mcRef.mcPopups.mcObjectives);
  77.       this.oObjectivesPopUp.Listener = this;
  78.       Main.Instance.doAddListener(this.oObjectivesPopUp);
  79.       this.oTransition = new Library.Transition(this.mcRef.mcTransition);
  80.       this.oTransition.Listener = this;
  81.       Main.Instance.doAddListener(this.oTransition);
  82.       this.oTransitionMiniGameStart = new Library.Transition(this.mcRef.mcTransitionMGStart);
  83.       this.oTransitionMiniGameStart.Listener = this;
  84.       Main.Instance.doAddListener(this.oTransitionMiniGameStart);
  85.       this.oTransitionMiniGameEnd = new Library.Transition(this.mcRef.mcTransitionMGEnd);
  86.       this.oTransitionMiniGameEnd.Listener = this;
  87.       Main.Instance.doAddListener(this.oTransitionMiniGameEnd);
  88.       this.oPlayerStatus = new PlayerStatus();
  89.       this.oGameTimer = new Library.Utils.Timer();
  90.       this.oGameTimer.FrameRate = Main.FRAME_RATE;
  91.       this.oGameTimer.Method = Library.Utils.Timer.TIMER_COUNT_DOWN;
  92.       Main.Instance.doAddListener(this);
  93.       this.bTimeOverTriggered = false;
  94.       if(__bStoryMode)
  95.       {
  96.          this.sPlayMode = Game.SECTION_LEVEL_SELECT_STORY;
  97.       }
  98.       else
  99.       {
  100.          this.sPlayMode = Game.SECTION_LEVEL_SELECT_USER;
  101.       }
  102.       this.doSetSection(this.sPlayMode);
  103.    }
  104.    static function get Instance()
  105.    {
  106.       return Game.oCtrl;
  107.    }
  108.    function doEnterFrame()
  109.    {
  110.       super.doEnterFrame();
  111.       if(this.nNeedInitialLevelPause != -1)
  112.       {
  113.          this.nNeedInitialLevelPause = this.nNeedInitialLevelPause + 1;
  114.          if(this.nNeedInitialLevelPause >= 3)
  115.          {
  116.             this.nNeedInitialLevelPause = -1;
  117.             this.oLevel.doPause();
  118.          }
  119.       }
  120.       if(this.nObjectivesCloseTimer > 0)
  121.       {
  122.          this.nObjectivesCloseTimer = this.nObjectivesCloseTimer - 1;
  123.          if(this.nObjectivesCloseTimer == 0)
  124.          {
  125.             this.oObjectivesPopUp.doClose();
  126.             this.oLevel.doResume();
  127.          }
  128.       }
  129.       else if(!this.oLevel.bPaused || !this.oMiniGame.bPaused)
  130.       {
  131.          this.oGameTimer.doEnterFrame();
  132.       }
  133.       if(this.sCurrentSection == Game.SECTION_GAME)
  134.       {
  135.          this.doWatchTime();
  136.          this.doUpdateHudPoints();
  137.       }
  138.    }
  139.    function doCreateNewLevel(__nRowNum)
  140.    {
  141.       delete this.oTargetLevelData;
  142.       this.nNewLevelTargetRow = __nRowNum;
  143.       this.doTransitionTo(Game.SECTION_EDITOR);
  144.    }
  145.    function onConfirmAnswer(__bAnswer)
  146.    {
  147.       if(__bAnswer)
  148.       {
  149.          if(this.nConfirmContext == Game.CONFIRM_CONTEXT_DELETE_LEVEL)
  150.          {
  151.             this.Status.doDeleteUserLevel(this.oLevelToDelete);
  152.             this.oLevelSelector.onLevelDeleted();
  153.          }
  154.          else if(this.nConfirmContext == Game.CONFIRM_CONTEXT_QUIT_GAME)
  155.          {
  156.             if(this.bTestingUserLevel)
  157.             {
  158.                this.doTransitionTo(Game.SECTION_EDITOR);
  159.                this.oConfirmPopUp.doClose();
  160.                this.oMenuPopUp.doClose();
  161.             }
  162.             else if(this.nPlayLevelType == BaseLevelData.LEVEL_TYPE_STORY)
  163.             {
  164.                Main.Instance.onPlayerLose(Main.LOSE_REASON_QUIT);
  165.             }
  166.             else
  167.             {
  168.                if(this.bTestingUserLevel)
  169.                {
  170.                   this.doEditLevel(this.oTargetLevelData);
  171.                }
  172.                else
  173.                {
  174.                   this.doTransitionTo(Game.SECTION_LEVEL_SELECT_USER);
  175.                }
  176.                this.oMenuPopUp.doClose();
  177.             }
  178.          }
  179.       }
  180.       this.oConfirmPopUp.doClose();
  181.       delete this.oLevelToDelete;
  182.    }
  183.    function doAskDeleteLevel(__oLevel)
  184.    {
  185.       this.sDeleteLevelName = __oLevel.LevelName;
  186.       this.oLevelToDelete = __oLevel;
  187.       this.nConfirmContext = Game.CONFIRM_CONTEXT_DELETE_LEVEL;
  188.       this.oConfirmPopUp.doOpen();
  189.    }
  190.    function doEditLevel(__oLevel)
  191.    {
  192.       this.oTargetLevelData = __oLevel;
  193.       this.doTransitionTo(Game.SECTION_EDITOR);
  194.    }
  195.    function doExitEditor()
  196.    {
  197.       this.doTransitionTo(Game.SECTION_LEVEL_SELECT_USER);
  198.    }
  199.    function doTestLevel(__oLevel)
  200.    {
  201.       this.bTestingUserLevel = true;
  202.       this.oTargetLevelData = __oLevel;
  203.       this.doTransitionTo(Game.SECTION_GAME);
  204.    }
  205.    function doStartLevel(__oLevel, _nLevelType)
  206.    {
  207.       this.bTestingUserLevel = false;
  208.       this.nPlayLevelType = _nLevelType;
  209.       this.oTargetLevelData = __oLevel;
  210.       this.doTransitionTo(Game.SECTION_GAME);
  211.    }
  212.    function onTakReachEnd()
  213.    {
  214.       if(this.nMoonStonesCatched >= this.oTargetLevelData.RequiredMS)
  215.       {
  216.          this.doLevelEnd(true);
  217.       }
  218.       else
  219.       {
  220.          this.doLevelEnd(false,Main.LOSE_REASON_MOONSTONES);
  221.       }
  222.    }
  223.    function doLevelEnd(__bWon, __nLoseReason)
  224.    {
  225.       this.oGameTimer.doStopTimer();
  226.       this.oLevel.doPause();
  227.       this.oMiniGame.doPause();
  228.       if(__bWon)
  229.       {
  230.          var _loc4_ = new BaseLevelData();
  231.          _loc4_.Completed = true;
  232.          _loc4_.RequiredMS = this.oTargetLevelData.RequiredMS;
  233.          _loc4_.TimeAllowed = this.oTargetLevelData.TimeAllowed;
  234.          _loc4_.TimeTaken = this.oTargetLevelData.TimeAllowed - this.oGameTimer.Time;
  235.          _loc4_.CollectedMS = this.nMoonStonesCatched;
  236.          _loc4_.MiniStones = this.nMiniStonesCatched;
  237.          if(_loc4_.Score > this.oTargetLevelData.Score)
  238.          {
  239.             this.oTargetLevelData.Completed = true;
  240.             this.oTargetLevelData.TimeTaken = this.oTargetLevelData.TimeAllowed - this.oGameTimer.Time;
  241.             this.oTargetLevelData.CollectedMS = this.nMoonStonesCatched;
  242.             this.oTargetLevelData.MiniStones = this.nMiniStonesCatched;
  243.             this.oTargetLevelData.doSave();
  244.          }
  245.          if(this.nPlayLevelType == BaseLevelData.LEVEL_TYPE_STORY)
  246.          {
  247.             var _loc7_ = this.oTargetLevelData.LevelNumber;
  248.             if(_loc7_ < this.Status.getLevelQuantity(this.LevelType))
  249.             {
  250.                var _loc6_ = this.Status.getLevelData(this.LevelType,_loc7_ + 1);
  251.                _loc6_.Locked = false;
  252.                _loc6_.doSave();
  253.             }
  254.             var _loc18_ = BaseLevelData.POINTS_BASE;
  255.             var _loc13_ = this.oTargetLevelData.RequiredMS;
  256.             var _loc9_ = BaseLevelData.POINTS_PER_MS_BASE;
  257.             var _loc14_ = _loc13_ * _loc9_;
  258.             var _loc15_ = this.nMoonStonesCatched - this.oTargetLevelData.RequiredMS;
  259.             var _loc11_ = BaseLevelData.POINTS_PER_MS_OVER;
  260.             var _loc10_ = _loc15_ * _loc11_;
  261.             var _loc17_ = this.nMiniStonesCatched;
  262.             var _loc19_ = BaseLevelData.POINTS_PER_MINISTONES;
  263.             var _loc8_ = _loc17_ * _loc19_;
  264.             var _loc12_ = this.oGameTimer.Time;
  265.             var _loc16_ = Math.floor(_loc12_ * BaseLevelData.POINTS_PER_MILLISECOND_REMAINING);
  266.             var _loc3_ = _loc18_ + _loc14_ + _loc10_ + _loc8_ + _loc16_;
  267.             if(Main.Instance.HSM.getIsLoggedIn())
  268.             {
  269.                this.nAwardedNPs = 0;
  270.                for(var _loc5_ in Game.aNP_BY_SCORE)
  271.                {
  272.                   var _loc2_ = Game.aNP_BY_SCORE[_loc5_];
  273.                   if(_loc2_.nMin <= _loc3_ && _loc2_.nMax >= _loc3_)
  274.                   {
  275.                      this.nAwardedNPs = _loc2_.nPts;
  276.                      break;
  277.                   }
  278.                }
  279.                Main.Instance.StageRoot.awardPoints(this.nAwardedNPs);
  280.             }
  281.          }
  282.          this.oWinPopUp.doOpen();
  283.       }
  284.       else if(this.sPlayMode == Game.SECTION_LEVEL_SELECT_STORY)
  285.       {
  286.          Main.Instance.onPlayerLose(__nLoseReason);
  287.       }
  288.       else
  289.       {
  290.          this.oULLosePopUp.doOpen();
  291.       }
  292.    }
  293.    function doProgressToNextLevel()
  294.    {
  295.       var _loc2_ = this.oTargetLevelData.LevelNumber;
  296.       this.oTargetLevelData = this.oPlayerStatus.getLevelData(this.LevelType,_loc2_ + 1);
  297.       this.doTransitionTo(Game.SECTION_GAME);
  298.    }
  299.    function doShowWinScreen()
  300.    {
  301.       Main.Instance.onPlayerWin();
  302.    }
  303.    function doShowLevelMap()
  304.    {
  305.       this.doTransitionTo(this.sPlayMode);
  306.    }
  307.    function onLostMoonstone()
  308.    {
  309.       this.nMoonStonesCatched = this.nMoonStonesCatched - 1;
  310.       this.nMoonStonesCatched = Math.max(0,this.nMoonStonesCatched);
  311.       this.oTestLevel.CollectedMS = this.nMoonStonesCatched;
  312.       this.mcRef.mcScreen.mcHud.txtMoonStones.text = Library.Utils.Tools.getFormatedNumber(this.nMoonStonesCatched,3);
  313.    }
  314.    function onCatchMoonstone()
  315.    {
  316.       Library.Sound.SoundManager.isSoundPlaying("Moonstone.mp3").oSound.doStop();
  317.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Moonstone.mp3");
  318.       this.nMoonStonesCatched = this.nMoonStonesCatched + 1;
  319.       this.oTestLevel.CollectedMS = this.nMoonStonesCatched;
  320.       this.mcRef.mcScreen.mcHud.txtMoonStones.text = Library.Utils.Tools.getFormatedNumber(this.nMoonStonesCatched,3);
  321.    }
  322.    function onCatchMiniStone()
  323.    {
  324.       Library.Sound.SoundManager.isSoundPlaying("Ministone.mp3").oSound.doStop();
  325.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Ministone.mp3");
  326.       this.nMiniStonesCatched = this.nMiniStonesCatched + 1;
  327.       this.oTestLevel.MiniStones = this.nMiniStonesCatched;
  328.    }
  329.    function onFeatherCatch()
  330.    {
  331.       this.oLevel.doPause();
  332.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Wind_Transition_In.mp3");
  333.       this.oTransitionMiniGameStart.doStart();
  334.    }
  335.    function doMinigameEnd()
  336.    {
  337.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Wind_Transition_Out.mp3");
  338.       this.oTransitionMiniGameEnd.doStart();
  339.    }
  340.    function onTransitionEvent(__nEvent, __oTransition)
  341.    {
  342.       switch(__nEvent)
  343.       {
  344.          case Library.Transition.TRANSITION_SCREEN_COVERED:
  345.             if(__oTransition == this.oTransition)
  346.             {
  347.                this.doUnloadSection(this.sCurrentSection);
  348.                this.doSetSection(this.sTargetSection);
  349.                Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"transition_out.mp3",60);
  350.             }
  351.             else
  352.             {
  353.                this.doToggleGameStatus();
  354.             }
  355.             break;
  356.          case Library.Transition.TRANSITION_COMPLETE:
  357.       }
  358.    }
  359.    function onPopUpEvent(__nEvent, __oPopUp)
  360.    {
  361.       if(__nEvent === Library.BasicPopUp.NEED_UPDATE)
  362.       {
  363.          switch(__oPopUp)
  364.          {
  365.             case this.oHelpPopUp:
  366.                this.doUpdateHelpPopUp();
  367.                break;
  368.             case this.oULLosePopUp:
  369.                this.doUpdateULLosePopUp();
  370.                break;
  371.             case this.oWinPopUp:
  372.                this.doUpdateWinPopUp();
  373.                break;
  374.             case this.oMenuPopUp:
  375.                this.doUpdateMenuPopUp();
  376.                break;
  377.             case this.oConfirmPopUp:
  378.                this.doUpdateConfirmPopUp();
  379.                break;
  380.             case this.oObjectivesPopUp:
  381.                this.doUpdateObjectivesPopUp();
  382.          }
  383.       }
  384.    }
  385.    function doSoundEvent(__nEvent, __oSound)
  386.    {
  387.       if(__nEvent === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
  388.       {
  389.          if(__oSound == this.oMusicGameGround)
  390.          {
  391.             delete this.oMusicGameGround;
  392.          }
  393.          else if(__oSound == this.oMusicGameSky)
  394.          {
  395.             delete this.oMusicGameSky;
  396.          }
  397.       }
  398.    }
  399.    function doStartMusic()
  400.    {
  401.       if(this.oMusicGameSky == undefined)
  402.       {
  403.          this.oMusicGameSky = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_MUSIC,"Game_Sky.wav",0,999999);
  404.          this.oMusicGameSky.doAddListener(this);
  405.          this.oMusicGameSky.setFadeRate(8);
  406.       }
  407.       if(this.oMusicGameGround == undefined)
  408.       {
  409.          this.oMusicGameGround = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_MUSIC,"Game_Ground.wav",0,999999);
  410.          this.oMusicGameGround.doAddListener(this);
  411.          this.oMusicGameGround.setFadeRate(8);
  412.       }
  413.    }
  414.    function doStopMusic()
  415.    {
  416.       if(this.oMusicGameSky != undefined)
  417.       {
  418.          this.oMusicGameSky.setFadeRate(8);
  419.          this.oMusicGameSky.doFadeTo(0);
  420.       }
  421.       if(this.oMusicGameGround != undefined)
  422.       {
  423.          this.oMusicGameGround.setFadeRate(8);
  424.          this.oMusicGameGround.doFadeTo(0);
  425.       }
  426.    }
  427.    function doStartMusicGround()
  428.    {
  429.       this.doStartMusic();
  430.       this.oMusicGameSky.setFadeRate(8);
  431.       this.oMusicGameGround.setFadeRate(8);
  432.       this.oMusicGameSky.doFadeTo(0,false);
  433.       this.oMusicGameGround.doFadeTo(100);
  434.    }
  435.    function doStartMusicSky()
  436.    {
  437.       this.doStartMusic();
  438.       this.oMusicGameSky.setFadeRate(2);
  439.       this.oMusicGameGround.setFadeRate(2);
  440.       this.oMusicGameGround.doFadeTo(0,false);
  441.       this.oMusicGameSky.doFadeTo(100);
  442.    }
  443.    function doToggleMuteFor(__sCategory)
  444.    {
  445.       if(Library.Sound.SoundManager.isCategoryMuted(__sCategory))
  446.       {
  447.          Library.Sound.SoundManager.doUnMuteCategory(__sCategory);
  448.       }
  449.       else
  450.       {
  451.          Library.Sound.SoundManager.doMuteCategory(__sCategory);
  452.       }
  453.       this.doUpdateMenuSoundGroups();
  454.    }
  455.    function doShowMenu()
  456.    {
  457.       if(this.oObjectivesPopUp.CurrentState == "Hidden")
  458.       {
  459.          this.oLevel.doPause();
  460.          this.oMiniGame.doPause();
  461.          this.oMenuPopUp.doOpen();
  462.          this.oGameTimer.doStopTimer();
  463.       }
  464.    }
  465.    function doCloseMenu()
  466.    {
  467.       if(this.nGameStatus == Game.GAME_STATUS_SIDESCROLLER)
  468.       {
  469.          this.oLevel.doResume();
  470.       }
  471.       else
  472.       {
  473.          this.oMiniGame.doResume();
  474.       }
  475.       this.oMenuPopUp.doClose();
  476.       this.oGameTimer.doStartTimer();
  477.    }
  478.    function doBackToTitle()
  479.    {
  480.       Main.Instance.onBackToTitle();
  481.    }
  482.    function doQuitGame()
  483.    {
  484.       this.nConfirmContext = Game.CONFIRM_CONTEXT_QUIT_GAME;
  485.       this.oConfirmPopUp.doOpen();
  486.    }
  487.    function doCloseHelp()
  488.    {
  489.       this.oHelpPopUp.doClose();
  490.       delete this.nLatestHelpPage;
  491.    }
  492.    function doShowHelp()
  493.    {
  494.       this.oHelpPopUp.doOpen();
  495.    }
  496.    function doInstructionPageChange(__nChange)
  497.    {
  498.       this.oHelpPopUp.Ref.gotoAndStop(this.oHelpPopUp.Ref._currentframe + __nChange);
  499.       this.nLatestHelpPage = this.oHelpPopUp.Ref._currentframe;
  500.       this.doUpdateHelpPopUp();
  501.    }
  502.    function doDestroy()
  503.    {
  504.       this.oMiniGame.doDestroy();
  505.       this.oLevel.doDestroy();
  506.       delete this.oMiniGame;
  507.       delete this.oLevel;
  508.       Main.Instance.doRemoveListener(this);
  509.       delete this.oGameTimer;
  510.       this.oMenuPopUp.doHide();
  511.       this.oWinPopUp.doHide();
  512.       this.doStopMusic();
  513.       Main.Instance.doStartPackMusic();
  514.    }
  515.    function get MSQty()
  516.    {
  517.       return this.nMoonStonesCatched;
  518.    }
  519.    function get Score()
  520.    {
  521.       var _loc4_ = 0;
  522.       var _loc5_ = undefined;
  523.       if(this.sPlayMode == Game.SECTION_LEVEL_SELECT_STORY)
  524.       {
  525.          var _loc2_ = 1;
  526.          while(_loc2_ <= Game.Instance.Status.getLevelQuantity(BaseLevelData.LEVEL_TYPE_STORY))
  527.          {
  528.             var _loc3_ = Game.Instance.Status.getLevelData(BaseLevelData.LEVEL_TYPE_STORY,_loc2_);
  529.             _loc4_ += _loc3_.Score;
  530.             _loc2_ = _loc2_ + 1;
  531.          }
  532.       }
  533.       else if(this.sPlayMode == Game.SECTION_LEVEL_SELECT_USER)
  534.       {
  535.          _loc4_ = this.oTargetLevelData.Score;
  536.       }
  537.       return _loc4_;
  538.    }
  539.    function get LevelType()
  540.    {
  541.       var _loc2_ = undefined;
  542.       if(this.sPlayMode == Game.SECTION_LEVEL_SELECT_STORY)
  543.       {
  544.          _loc2_ = BaseLevelData.LEVEL_TYPE_STORY;
  545.       }
  546.       else if(this.sPlayMode == Game.SECTION_LEVEL_SELECT_USER)
  547.       {
  548.          _loc2_ = BaseLevelData.LEVEL_TYPE_USER;
  549.       }
  550.       return _loc2_;
  551.    }
  552.    function get Editor()
  553.    {
  554.       return this.oLevelEditor;
  555.    }
  556.    function get Status()
  557.    {
  558.       return this.oPlayerStatus;
  559.    }
  560.    function doUpdateHudPoints()
  561.    {
  562.       this.nCurrentShownScore = Library.Utils.MoreMath.getReachNum(this.nCurrentShownScore,this.oTestLevel.Score - BaseLevelData.POINTS_BASE,Game.HUD_POINTS_UPDATE_RATE);
  563.       this.mcRef.mcScreen.mcHud.txtScore.text = Library.Utils.Tools.getFormatedNumber(this.nCurrentShownScore,6);
  564.    }
  565.    function doWatchTime()
  566.    {
  567.       this.mcRef.mcScreen.mcHud.txtTime.text = Library.Utils.Tools.getFormatedTime(this.oGameTimer.Time,false);
  568.       if(this.oGameTimer.Time <= 0 && !this.bTimeOverTriggered)
  569.       {
  570.          this.bTimeOverTriggered = true;
  571.          this.doLevelEnd(false,Main.LOSE_REASON_TIMEOUT);
  572.       }
  573.    }
  574.    function doToggleGameStatus()
  575.    {
  576.       if(this.nGameStatus == Game.GAME_STATUS_SIDESCROLLER)
  577.       {
  578.          this.mcRef.mcScreen.mcSS._visible = false;
  579.          this.mcRef.mcScreen.mcMG._visible = true;
  580.          this.doCreateMiniGame();
  581.          this.doStartMusicSky();
  582.       }
  583.       else
  584.       {
  585.          this.mcRef.mcScreen.mcSS._visible = true;
  586.          this.mcRef.mcScreen.mcMG._visible = false;
  587.          this.oMiniGame.doDestroy();
  588.          this.oLevel.doResumeFromMiniGame();
  589.          this.doStartMusicGround();
  590.          this.nGameStatus = Game.GAME_STATUS_SIDESCROLLER;
  591.       }
  592.    }
  593.    function doUpdateHelpPopUp()
  594.    {
  595.       if(this.nLatestHelpPage != undefined)
  596.       {
  597.          this.oHelpPopUp.Ref.gotoAndStop(this.nLatestHelpPage);
  598.       }
  599.       else
  600.       {
  601.          this.oHelpPopUp.Ref.stop();
  602.       }
  603.       this.oHelpPopUp.Ref.btnPlay.onRelease = Library.Utils.Delegate.create(this,this.doCloseHelp);
  604.       this.oHelpPopUp.Ref.btnPlay.onRelease = Library.Utils.Delegate.create(this,this.doCloseHelp);
  605.       this.oHelpPopUp.Ref.btnNext.onRelease = Library.Utils.Delegate.create(this,this.doInstructionPageChange,1);
  606.       this.oHelpPopUp.Ref.btnBack.onRelease = Library.Utils.Delegate.create(this,this.doInstructionPageChange,-1);
  607.    }
  608.    function doUpdateObjectivesPopUp()
  609.    {
  610.       this.oObjectivesPopUp.Ref.txtMoonstones.text = this.oTargetLevelData.RequiredMS;
  611.       this.oObjectivesPopUp.Ref.txtTime.text = Library.Utils.Tools.getFormatedTime(this.oTargetLevelData.TimeAllowed,false);
  612.    }
  613.    function doUpdateConfirmPopUp()
  614.    {
  615.       if(this.nConfirmContext == Game.CONFIRM_CONTEXT_DELETE_LEVEL)
  616.       {
  617.          this.oConfirmPopUp.Ref.mcText.gotoAndStop(1);
  618.          this.oConfirmPopUp.Ref.mcText.txtName.text = this.sDeleteLevelName;
  619.       }
  620.       else if(this.nConfirmContext == Game.CONFIRM_CONTEXT_QUIT_GAME)
  621.       {
  622.          this.oConfirmPopUp.Ref.mcText.gotoAndStop(2);
  623.       }
  624.       this.oConfirmPopUp.Ref.btnYes.onRelease = Library.Utils.Delegate.create(this,this.onConfirmAnswer,true);
  625.       this.oConfirmPopUp.Ref.btnNo.onRelease = Library.Utils.Delegate.create(this,this.onConfirmAnswer,false);
  626.    }
  627.    function doUpdateMenuPopUp()
  628.    {
  629.       this.oMenuPopUp.Ref.btnResume.onRelease = Library.Utils.Delegate.create(this,this.doCloseMenu);
  630.       this.oMenuPopUp.Ref.btnHelp.onRelease = Library.Utils.Delegate.create(this,this.doShowHelp);
  631.       this.oMenuPopUp.Ref.btnQuit.onRelease = Library.Utils.Delegate.create(this,this.doQuitGame);
  632.       this.doUpdateMenuSoundGroups();
  633.    }
  634.    function doUpdateMenuSoundGroups()
  635.    {
  636.       var _loc2_ = "On";
  637.       if(Library.Sound.SoundManager.isCategoryMuted(Main.SOUND_CAT_SOUND))
  638.       {
  639.          _loc2_ = "Off";
  640.       }
  641.       var _loc3_ = "On";
  642.       if(Library.Sound.SoundManager.isCategoryMuted(Main.SOUND_CAT_MUSIC))
  643.       {
  644.          _loc3_ = "Off";
  645.       }
  646.       this.oMenuPopUp.Ref.mcSoundToggle.gotoAndStop(_loc2_);
  647.       this.oMenuPopUp.Ref.mcMusicToggle.gotoAndStop(_loc3_);
  648.       this.oMenuPopUp.Ref.mcSoundToggle.btnToggle.onRelease = Library.Utils.Delegate.create(this,this.doToggleMuteFor,Main.SOUND_CAT_SOUND);
  649.       this.oMenuPopUp.Ref.mcMusicToggle.btnToggle.onRelease = Library.Utils.Delegate.create(this,this.doToggleMuteFor,Main.SOUND_CAT_MUSIC);
  650.    }
  651.    function doUpdateULLosePopUp()
  652.    {
  653.       if(this.bTestingUserLevel)
  654.       {
  655.          this.oULLosePopUp.Ref.mcButtons.gotoAndStop(1);
  656.          this.oULLosePopUp.Ref.mcButtons.btnReturn.onRelease = Library.Utils.Delegate.create(this,this.doEditLevel,this.oTargetLevelData);
  657.       }
  658.       else
  659.       {
  660.          this.oULLosePopUp.Ref.mcButtons.gotoAndStop(2);
  661.          this.oULLosePopUp.Ref.mcButtons.btnReturn.onRelease = Library.Utils.Delegate.create(this,this.doTransitionTo,Game.SECTION_LEVEL_SELECT_USER);
  662.       }
  663.    }
  664.    function doUpdateWinPopUp()
  665.    {
  666.       var _loc11_ = undefined;
  667.       if(this.sPlayMode == Game.SECTION_LEVEL_SELECT_STORY)
  668.       {
  669.          _loc11_ = BaseLevelData.LEVEL_TYPE_STORY;
  670.       }
  671.       else if(this.sPlayMode == Game.SECTION_LEVEL_SELECT_USER)
  672.       {
  673.          _loc11_ = BaseLevelData.LEVEL_TYPE_USER;
  674.       }
  675.       var _loc15_ = this.oTargetLevelData.LevelNumber;
  676.       var _loc17_ = this.oPlayerStatus.getLevelQuantity(_loc11_);
  677.       if(this.nPlayLevelType == BaseLevelData.LEVEL_TYPE_STORY)
  678.       {
  679.          if(_loc15_ >= _loc17_)
  680.          {
  681.             this.oWinPopUp.Ref.mcButtons.gotoAndStop("EndLevel");
  682.             this.oWinPopUp.Ref.mcButtons.btnContinue.onRelease = Library.Utils.Delegate.create(this,this.doShowWinScreen);
  683.          }
  684.          else
  685.          {
  686.             this.oWinPopUp.Ref.mcButtons.gotoAndStop("NormalPlay");
  687.             this.oWinPopUp.Ref.mcButtons.btnLevel.onRelease = Library.Utils.Delegate.create(this,this.doShowLevelMap);
  688.             this.oWinPopUp.Ref.mcButtons.btnNext.onRelease = Library.Utils.Delegate.create(this,this.doProgressToNextLevel);
  689.          }
  690.       }
  691.       else
  692.       {
  693.          this.oWinPopUp.Ref.mcButtons.gotoAndStop("Testing");
  694.          this.oWinPopUp.Ref.mcButtons.btnReturn.onRelease = Library.Utils.Delegate.create(this,this.doEditLevel,this.oTargetLevelData);
  695.       }
  696.       var _loc13_ = BaseLevelData.POINTS_BASE;
  697.       var _loc7_ = this.oTargetLevelData.RequiredMS;
  698.       var _loc3_ = BaseLevelData.POINTS_PER_MS_BASE;
  699.       var _loc8_ = _loc7_ * _loc3_;
  700.       var _loc9_ = this.nMoonStonesCatched - this.oTargetLevelData.RequiredMS;
  701.       var _loc5_ = BaseLevelData.POINTS_PER_MS_OVER;
  702.       var _loc4_ = _loc9_ * _loc5_;
  703.       var _loc12_ = this.nMiniStonesCatched;
  704.       var _loc14_ = BaseLevelData.POINTS_PER_MINISTONES;
  705.       var _loc2_ = _loc12_ * _loc14_;
  706.       var _loc6_ = this.oGameTimer.Time;
  707.       var _loc10_ = Math.floor(_loc6_ * BaseLevelData.POINTS_PER_MILLISECOND_REMAINING);
  708.       var _loc16_ = _loc13_ + _loc8_ + _loc4_ + _loc2_ + _loc10_;
  709.       this.oWinPopUp.Ref.txtCompleteBonus.text = Library.Utils.Tools.getFormatedNumber(_loc13_);
  710.       this.oWinPopUp.Ref.txtReqMSNum.text = Library.Utils.Tools.getFormatedNumber(_loc7_,2);
  711.       this.oWinPopUp.Ref.txtReqMSPts.text = Library.Utils.Tools.getFormatedNumber(_loc3_);
  712.       this.oWinPopUp.Ref.txtReqMSTotal.text = Library.Utils.Tools.getFormatedNumber(_loc8_);
  713.       this.oWinPopUp.Ref.txtAddMSNum.text = Library.Utils.Tools.getFormatedNumber(_loc9_,2);
  714.       this.oWinPopUp.Ref.txtAddMSPts.text = Library.Utils.Tools.getFormatedNumber(_loc5_);
  715.       this.oWinPopUp.Ref.txtAddMSTotal.text = Library.Utils.Tools.getFormatedNumber(_loc4_);
  716.       this.oWinPopUp.Ref.txtGemsNum.text = Library.Utils.Tools.getFormatedNumber(_loc12_,2);
  717.       this.oWinPopUp.Ref.txtGemsPts.text = Library.Utils.Tools.getFormatedNumber(_loc14_);
  718.       this.oWinPopUp.Ref.txtGemsTotal.text = Library.Utils.Tools.getFormatedNumber(_loc2_);
  719.       this.oWinPopUp.Ref.txtTime.text = Library.Utils.Tools.getFormatedTime(_loc6_,true);
  720.       this.oWinPopUp.Ref.txtTimeTotal.text = Library.Utils.Tools.getFormatedNumber(_loc10_);
  721.       this.oWinPopUp.Ref.txtScoreFinal.text = Library.Utils.Tools.getFormatedNumber(_loc16_);
  722.       if(Main.Instance.HSM.getIsLoggedIn() && this.sPlayMode == Game.SECTION_LEVEL_SELECT_STORY)
  723.       {
  724.          this.oWinPopUp.Ref.mcNP.txtPts.text = this.nAwardedNPs;
  725.       }
  726.       else
  727.       {
  728.          this.oWinPopUp.Ref.mcNP._visible = false;
  729.       }
  730.    }
  731.    function doCreateLevelEditor()
  732.    {
  733.       var _loc2_ = false;
  734.       if(this.oTargetLevelData != undefined)
  735.       {
  736.          _loc2_ = true;
  737.       }
  738.       var _loc3_ = new LevelEditor(this.mcRef.mcScreen,_loc2_,this.oTargetLevelData,this.nNewLevelTargetRow);
  739.    }
  740.    function doCreateLevelSelector(__nLevelType)
  741.    {
  742.       this.oLevelSelector = new LevelSelector(this.mcRef.mcScreen,__nLevelType);
  743.       this.mcRef.mcScreen.btnQuit.onRelease = Library.Utils.Delegate.create(this,this.doBackToTitle);
  744.    }
  745.    function doCreateMiniGame()
  746.    {
  747.       this.nGameStatus = Game.GAME_STATUS_MINIGAME;
  748.       this.oMiniGame = new MiniGameManager(this.mcRef.mcScreen.mcMG);
  749.    }
  750.    function doCreateLevel()
  751.    {
  752.       this.nGameStatus = Game.GAME_STATUS_SIDESCROLLER;
  753.       this.nMoonStonesCatched = 0;
  754.       this.nMiniStonesCatched = 0;
  755.       this.nCurrentShownScore = 0;
  756.       this.mcRef.mcScreen.mcHud.txtMoonStones.text = Library.Utils.Tools.getFormatedNumber(this.nMoonStonesCatched,3);
  757.       this.mcRef.mcScreen.mcHud.mcInvincibility._visible = Main.Instance.CodeBoxManager.Invincible;
  758.       this.bTimeOverTriggered = false;
  759.       this.oLevel = new LevelManager(this.mcRef.mcScreen.mcSS,this.oTargetLevelData);
  760.       this.mcRef.mcScreen.mcHud.btnMenu.onRelease = Library.Utils.Delegate.create(this,this.doShowMenu);
  761.       this.nNeedInitialLevelPause = 0;
  762.       this.oTestLevel = new BaseLevelData();
  763.       this.oTestLevel.Completed = true;
  764.       this.oTestLevel.RequiredMS = this.oTargetLevelData.RequiredMS;
  765.       this.oTestLevel.CollectedMS = 0;
  766.       this.oTestLevel.MiniStones = 0;
  767.       this.oTestLevel.TimeAllowed = this.oTargetLevelData.TimeAllowed;
  768.       this.oTestLevel.TimeTaken = this.oTargetLevelData.TimeAllowed;
  769.       this.oGameTimer.setTime(this.oTargetLevelData.TimeAllowed + 150);
  770.       this.oGameTimer.doStartTimer();
  771.       this.oObjectivesPopUp.doOpen();
  772.       this.nObjectivesCloseTimer = 90;
  773.       this.doUpdateHudPoints();
  774.       Main.Instance.doStopPackMusic();
  775.       this.doStartMusicGround();
  776.    }
  777.    function doUnloadEditor()
  778.    {
  779.       this.oLevelEditor.doDestroy();
  780.       delete this.oLevelEditor;
  781.    }
  782.    function doUnloadSelector()
  783.    {
  784.       this.oLevelSelector.doDestroy();
  785.       delete this.oLevelSelector;
  786.    }
  787.    function doUnloadLevel()
  788.    {
  789.       this.oWinPopUp.doHide();
  790.       this.oULLosePopUp.doHide();
  791.       this.oLevel.doRemoveListener(this.oGameTimer);
  792.       this.oLevel.doDestroy();
  793.       delete this.oLevel;
  794.       this.doStopMusic();
  795.       Main.Instance.doStartPackMusic();
  796.    }
  797.    function doSetSection(__sSection)
  798.    {
  799.       this.sCurrentSection = __sSection;
  800.       this.mcRef.gotoAndStop(this.sCurrentSection);
  801.       switch(this.sCurrentSection)
  802.       {
  803.          case Game.SECTION_LEVEL_SELECT_STORY:
  804.             this.doCreateLevelSelector(BaseLevelData.LEVEL_TYPE_STORY);
  805.             break;
  806.          case Game.SECTION_LEVEL_SELECT_USER:
  807.             this.doCreateLevelSelector(BaseLevelData.LEVEL_TYPE_USER);
  808.             break;
  809.          case Game.SECTION_GAME:
  810.             this.doCreateLevel();
  811.             break;
  812.          case Game.SECTION_EDITOR:
  813.             this.doCreateLevelEditor();
  814.       }
  815.    }
  816.    function doUnloadSection(__sSection)
  817.    {
  818.       switch(__sSection)
  819.       {
  820.          case Game.SECTION_LEVEL_SELECT_STORY:
  821.          case Game.SECTION_LEVEL_SELECT_USER:
  822.             this.doUnloadSelector();
  823.             break;
  824.          case Game.SECTION_EDITOR:
  825.             this.doUnloadEditor();
  826.             break;
  827.          case Game.SECTION_GAME:
  828.             this.doUnloadLevel();
  829.       }
  830.    }
  831.    function doTransitionTo(__sSection)
  832.    {
  833.       this.sTargetSection = __sSection;
  834.       this.oTransition.doStart();
  835.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"transition_in.mp3",60);
  836.    }
  837. }
  838.